package test00.lx04.t02;

import test00.lx04.t01.ComparatorImpl;
import test00.lx04.t01.Student;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author ZQX
 * @date 2025-04-07
 */
public class MainTest {
    public static void main(String[] args) {
        Student[] arrStudents = {
                new Student("张三",18) ,
                new Student("李四",8) ,
                new Student("王五",38) ,
                new Student("赵六",28) ,
                new Student("田七",7) ,
        } ;

        // 实例化 Comparator 接口对象 - 匿名内部类实现接口
        Comparator<Student> comparator = new Comparator<>(){

            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge()-o1.getAge();
            }
        } ;

        Arrays.sort(arrStudents, comparator) ;

        for (Student stu : arrStudents) {
            System.out.println(stu);
        }
    }
}
